<?php

namespace App\Providers;


use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema;
use Monolog\Logger;
use Yansongda\Pay\Pay;


class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        if( $this->app->environment () !== 'production' ){
            $this->app->register ( \Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class );
        }
        //往服务容器中注入一个 名为 alipay 的单列对象
        $this->app->singleton ( 'alipay' , function ()
        {
            $config = config ( 'pay.alipay' );
            //$config['notify_url'] = route('payment.alipay.notify_url');
            $config['notify_url'] = 'https://requestbin.leo108.com/uj893zuj';
            $config['return_url'] = route('payment.alipay.return_url');
            // 判断当前项目运行环境是否为线上环境
            if( $this->app->environment () !== 'production' ){
                $config[ 'mode' ]           = 'dev';
                $config[ 'log' ][ 'level' ] = Logger::DEBUG;
            }else{
                $config[ 'log' ][ 'level' ] = Logger::WARNING;
            }

            // 调用 Yansongda\Pay 来创建一个支付宝支付对象
            return Pay::alipay ( $config );
        } );

        $this->app->singleton('wechat_pay', function () {
            $config = config('pay.wechat');
            $config['notify_url'] = 'https://requestbin.leo108.com/187gbe91';
            if (app()->environment() !== 'production') {
                $config['log']['level'] = Logger::DEBUG;
            } else {
                $config['log']['level'] = Logger::WARNING;
            }
            // 调用 Yansongda\Pay 来创建一个微信支付对象
            return Pay::wechat($config);
        });
    }


    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        Schema::defaultStringLength ( 191 );
        //
    }
}
